package stockblaster.client;

import java.util.HashMap;
import java.util.LinkedList;

public class StockUser {
	private String username;
	private String password;
	private Double fund;
	private int helpNum;
	
	private String[] help;
	private String[] objectives;
	private static int month = 1;
	
	private boolean firstFourTriggered;
	
	//<CompanyName, number of shares that user has>
	private HashMap<String, Integer> shares;
	
	//LinkedList as container for company names whose part of the shares
	//  are owned by user
	private LinkedList<String> companyNames;
	
	public StockUser(String uName, String pass, Double _fund) {
		shares = new HashMap<String, Integer>();
		companyNames = new LinkedList<String>();
		if (uName.equals("Januardo Jankowski")) {
			help = HelpText.helpArdo;
			objectives = ObjectiveText.objectiveArdo;
		} else {
			//this is to prevent crash
			help = HelpText.helpArdo;
			objectives = ObjectiveText.objectiveArdo;
		}
		username = uName;
		password = pass;
		fund = _fund;
		helpNum = 0;
	}
	
	public void addMonth() {
		month++;
		if (month > 12)
			resetMonth();
	}
	
	public int getMonth() {
		return month;
	}
	
	public void resetMonth() {
		month = 1;
	}
	
	public void addHelpNum() {
		++helpNum;
	}
	
	public int getHelpNum() {
		return helpNum;
	}
	
	public void setFirstFourTriggered(boolean _b) {
		firstFourTriggered = _b;
	}
	
	public boolean getFirstFourTriggered() {
		return firstFourTriggered;
	}
	
	/**
	 * Method to get help
	 * @param uName the username
	 * @return user's help
	 */
	public String[] getHelp() {
		return help;
	}
	
	public String[] getObjectives() {
		return objectives;
	}
	
	/**
	 * Method to get user's fund
	 * @return Double value of user's fund
	 */
	public Double getFund() {
		return fund;
	}
	
	/**
	 * Method to add user's fund. For example because of selling shares.
	 * @param value the fund to add
	 */
	public void addFund(Double value) {
		this.fund += value;
	}
	
	/**
	 * Method to take away fund. For example because of buying shares.
	 * @param value the fund to take away
	 */
	public void takeFund(Double value) {
		this.fund -= value;
	}
	
	/**
	 * Method to set the user's fund
	 * @param value the fund to be set
	 */
	public void setFund(Double value) {
		this.fund = value;
	}
	
	/**
	 * Method to get the username
	 * @return the username
	 */
	public String getUsername() {
		return username;
	}
	
	/**
	 * Method to get the password
	 * @return the password of the user
	 */
	public String getPassword() {
		return password;
	}
	
	/**
	 * Method to add share into the our local data
	 * @param companyName the company name
	 * @param ss the object StockShares
	 */
	public void addShare(String companyName, Integer share) {
		if (shares.containsKey(companyName)) {
			shares.put(companyName, share);
		} else {
			shares.put(companyName, share);
			companyNames.add(companyName);
		}
	}
	
	/**
	 * Method to remove the company where user has shares at
	 * @param companyName the company to get removed from user's shares list
	 * @return true if successful; false otherwise
	 */
	public boolean removeCompanyShare(String companyName) {
		if (shares.containsKey(companyName)) {
			shares.remove(companyName);
			companyNames.remove(companyName);
			return true;
		} else {
			return false;
		}
	}
	
	/**
	 * Method to get the number of stock shares
	 * @param companyName the company which has your shares
	 * @return the number of shares that user has in that company
	 */
	public Integer getShares(String companyName) {
		return shares.get(companyName);
	}
	
	/**
	 * Method to get all shares that user has
	 * @return the HashMap<String, Integer> object
	 */
	public HashMap<String, Integer> getShares() {
		return shares;
	}
	
	/**
	 * Method to get all the company names where user has shares at
	 * @return the company names
	 */
	public LinkedList<String> getCompanyNames() {
		return companyNames;
	}
}
